#include "WDRequest.h"


CWDRequest::CWDRequest(void)
{
}


CWDRequest::~CWDRequest(void)
{
}


int CWDRequest::ResponseAnalysis(void)
{
	m_pcCopyParse = m_cCopyBuf;

	switch (*m_pcCopyParse)
	{
	case '2':
		if (m_nState == m_kCWDenum::PWD)
		{
			ResponsePWD();
			if (m_bCWD)
			{
				sprintf(m_cSendBuf, "CWD %s%s\r\n", m_cServPath, m_cFileName);
				send(m_nConn, m_cSendBuf, strlen(m_cSendBuf), 0);
				m_bCWD = false;
				m_nState = m_kCWDenum::CWD;
			}
			else
			{
				send(m_nConn, "PASV\r\n", 6, 0);
				m_nState = m_kCWDenum::PASV;
			}
		}
		else if (m_nState == m_kCWDenum::PASV)
		{
			ResponsePASV();
			CreateDataConn();
			PutItemList();
			m_nState = m_kCWDenum::NONE;
		}
		else if (m_nState == m_kCWDenum::CWD)
		{
			send(m_nConn, "PWD\r\n", 5, 0);
			m_nState = m_kCWDenum::PWD;
		}
		break;

	case '4':
		//make Data connection failed handle
		m_nState = m_kCWDenum::NONE;
		AfxMessageBox(m_cCopyBuf);
		break;

	case '5':
		//make Data connection failed handle
		m_nState = m_kCWDenum::NONE;
		AfxMessageBox(m_cCopyBuf);
		break;
	}
	return 0;
}

void CWDRequest::SendCWD(void)
{
	send(m_nConn, "PWD\r\n", 5, 0);
	m_bCWD = true;
	m_nState = m_kCWDenum::PWD;
}

